<template>
    <div>
    <el-form inline class="demo-form-inline">
    <el-row >
        <el-col :span="5">
            <el-form-item label="等级名称">
                <el-input v-model="query.payload.name" placeholder="等级名称" />
            </el-form-item>
        </el-col>
        <el-col :span="5">
            <el-form-item label="默认等级">
                <el-select v-model="query.payload.defaultStatus" placeholder="请选择">
                    <el-option label="是" :value = "1+''" />
                    <el-option label="否" :value = "0+''" />
                </el-select>
            </el-form-item>
        </el-col>
        <el-col :span="5">
            <el-form-item label="免运费标准">
                <el-input v-model="query.payload.freeFreightPoint" placeholder="免运费标准" />
            </el-form-item>
        </el-col>
    </el-row>
    <el-row >
        <el-form-item label="创建时间">
            <el-date-picker
                    v-model="query.dateRange"
                    type="datetimerange"
                    range-separator="到"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
            />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" activity @click="queryUmsMemberLevel">查询</el-button>
            <el-button type="warning" activity @click="reset">重置</el-button>
            <el-button type="success" @click="addUmsMemberLevel">新增</el-button>
        </el-form-item>
    </el-row>
    </el-form>
    <el-divider style="margin: 12px 0"/>
    <el-table ref="table" border v-loading="loading"  :data="data.tableData" header-cell-class-name="headerClass">
        <el-table-column align="center" type="index"  label="序号" width="100px" />
        <el-table-column align="center" prop="name" label="等级名称" />
        <el-table-column align="center" prop="growthPoint" label="等级需要的成长值" />
        <el-table-column align="center" prop="defaultStatus" label="是否为默认等级" >
            <template #default="scope">
                <el-icon :size="17" v-if="scope.row.defaultStatus===1"><CircleCheckFilled /></el-icon>
                <el-icon :size="17" v-else><CircleCloseFilled /></el-icon>
            </template>
        </el-table-column>
        <el-table-column align="center" prop="freeFreightPoint" label="免运费标准" />
        <el-table-column align="center" prop="commentGrowthPoint" label="每次评价获取的成长值" />
        <el-table-column align="center" prop="priviledgeFreeFreight" label="是否有免邮特权" >
            <template #default="scope">
                <el-icon :size="17" v-if="scope.row.priviledgeFreeFreight===1"><CircleCheckFilled /></el-icon>
                <el-icon :size="17" v-else><CircleCloseFilled /></el-icon>
            </template>
        </el-table-column>
        <el-table-column align="center" prop="priviledgeMemberPrice" label="是否有会员价格特权" >
            <template #default="scope">
                <el-icon :size="17" v-if="scope.row.priviledgeMemberPrice===1"><CircleCheckFilled /></el-icon>
                <el-icon :size="17" v-else><CircleCloseFilled /></el-icon>
            </template>
        </el-table-column>
        <el-table-column align="center" prop="priviledgeBirthday" label="是否有生日特权" >
            <template #default="scope">
                <el-icon :size="17" v-if="scope.row.priviledgeBirthday===1"><CircleCheckFilled /></el-icon>
                <el-icon :size="17" v-else><CircleCloseFilled /></el-icon>
            </template>
        </el-table-column>
        <el-table-column align="center" prop="note" label="备注" />
        <el-table-column align="center" label="操作">
            <template #default="scope">
                <el-link title="修改" type="primary" @click="editUmsMemberLevel(scope.row.id)">
                    <el-icon :size="20">
                        <Edit />
                    </el-icon>
                    修改
                </el-link>
                &nbsp;
                <el-popconfirm title="删除？" @confirm="deleteUmsMemberLevel(scope.row.id)"  @cancel="">
                    <template #reference>
                        <el-link type="danger" title="删除">
                            <el-icon :size="20">
                                <Delete />
                            </el-icon>
                            删除
                        </el-link>
                    </template>
                </el-popconfirm>
            </template>
        </el-table-column>
</el-table>
<el-pagination
        style="display: flex;align-items:center;justify-content:center;"
        v-model:currentPage="query.currentPage"
        v-model:page-size="query.pageSize"
        :page-sizes="[10, 20, 30]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="query.total"
        @size-change="queryUmsMemberLevel"
        @current-change="queryUmsMemberLevel"
/>
<ModUmsMemberLevel @close="modUmsMemberLevel.isOpen = false"  @reload="queryUmsMemberLevel"
              ref="modUmsMemberLevel"
              :openType="transData.openType"
              :id="transData.id" />
</div>
</template>

<script setup>
    import ModUmsMemberLevel from '@/views/mall/ums/components/ModUmsMemberLevel.vue'
    import request from '@/utils/request.js'
    import { ElMessage } from 'element-plus'
    import {ref, reactive, onMounted} from 'vue'
    import moment from 'moment'
    let transData = reactive({})
    let modUmsMemberLevel = ref(null)
    let data = reactive({
        modRole:false,
        tableData:[],
        openType:"",
        id:"",
    });
    let loading = ref(true)
    let query = reactive({dateRange:[],payload:{}, currentPage:1,pageSize:10,total:0})
    onMounted(() => {
        queryUmsMemberLevel()
    })
    function queryUmsMemberLevel(){
        query.startTime = query.dateRange[0]
        query.endTime = query.dateRange[1]
        request.post("/api/umsMemberLevel/getUmsMemberLevelPage", query).then(resp => {
            data.tableData = resp.records
            query.total = resp.total
            loading.value = false
        })
    }

    function reset(){
            query.payload.name = ""
            query.payload.growthPoint = ""
            query.payload.defaultStatus = ""
            query.payload.freeFreightPoint = ""
            query.payload.commentGrowthPoint = ""
            query.payload.priviledgeFreeFreight = ""
            query.payload.priviledgeMemberPrice = ""
            query.payload.priviledgeBirthday = ""
            query.payload.note = ""
    }

    function addUmsMemberLevel(){
        transData.openType = "add"
        modUmsMemberLevel.value.isOpen = true
    }

    function deleteUmsMemberLevel(id){
        request.get(`/api/umsMemberLevel/delete/${id}`).then(resp => {
            queryUmsMemberLevel()
            ElMessage({message: '删除成功！',openType: 'success'})
        });
    }

    function editUmsMemberLevel(id){
        transData.id = id
        transData.openType = "edit"
        modUmsMemberLevel.value.isOpen = true
    }

</script>
<style lang="css">

</style>


